import Router from '../../utils/router';
import base from '../../config/base.js';
import service from '../../services/aftersale';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    companyArr: [],
    icon_right: base.static + 'aftersale/titlearrow.png',
    comValue: '点击选择',
    inValue: '', //物流单号
    checked: true,
    orid: '',
    srorid: '',
    express_id: '', //提交物流对应id
    companyArr: '', //物流名称集合
    },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      srorid: options.srorid,
      orid: options.orid
    })
    this.getCompany();
  },
  //加载物流公司
  getCompany: function(){
    let that = this;
    let params = {}
    service.saleAfterGetExpress(params, function (res) {
      if (res && res.code == 1) {
        that.setData({
          companyArr: res.data.express,
        });
      }
    });
  },
  //选择物流公司
  bindPickerChange: function(e){
    let that = this;
    let array = that.data.companyArr
    that.setData({
      comValue: array[e.detail.value].express_company,
      express_id: array[e.detail.value].express_id,
      checked: false
    })
  },
  //输入框输入
  inputs: function(e){
    let that = this;
    that.setData({
      inValue: e.detail.value
    })
  },
  //提交物流
  subCompany: function () {
    let that = this;
    let reg = /^[1-9]\d*$/;
    if (that.data.express_id == "" || that.data.inValue == "") {
      wx.showToast({
        title: '您还没有选择物流或填写单号',
        icon: 'none'
      })
      return
    }
    if (!reg.test(that.data.inValue)) {
      wx.showToast({
        title: '物流单号填写错误',
        icon: 'none'
      })
      return
    }
    let params = {
      srorid: that.data.srorid,
      express_id: that.data.express_id,
      saleafter_logistics: that.data.inValue
    }
    service.saleAfterUpdate(params, function (res) {
      if (res && res.code == 1) {
        Router.go('afterdetail', `srorid=${that.data.srorid}&orid=${that.data.orid}`);
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },
})